import { CoolController } from "@cool-midway/core";
import { ProviderCertificateEntity } from "../../entity/certificate";
import { ProviderCertificateService } from "../../service/certificate";
import { BaseController } from "@cool-midway/core";
import { Body, Inject, Post } from "@midwayjs/core";
import { AuditCertificateDTO } from "../../dto/certificate";
import { Validate } from "@midwayjs/validate";
import { ProviderProfileEntity } from "../../entity/profile";

@CoolController({
    api: ['add', 'update', 'delete', 'info', 'list', 'page'],
    entity: ProviderCertificateEntity,
    service: ProviderCertificateService,
    pageQueryOp: {
        keyWordLikeFields: ['b.name', 'a.number'],
        fieldEq: ['a.type', 'a.status'],
        select: ['a.*', 'b.name as providerName'],
        join: [
            {
                entity: ProviderProfileEntity,
                alias: 'b',
                condition: 'a.providerId = b.providerId',
                type: 'leftJoin'
            }
        ]
    }
})
export class AdminProviderCertificateController extends BaseController {
    @Inject()
    providerCertificateService: ProviderCertificateService;

    @Validate()
    @Post('/audit', { summary: '审核证件信息' })
    async audit(@Body() dto: AuditCertificateDTO) {
        return this.ok(await this.providerCertificateService.auditCertificate(dto));
    }
}